package com.atrix.CinemaView.pojo.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("Json返回值基础对象")
public class R<T> {
    @ApiModelProperty("请求是否成功")
    boolean success;
    @ApiModelProperty("请求返回数据")
    T data;
    @ApiModelProperty("请求返回消息")
    String message;

    private R() {
    }

    public static <T> R<T> success() {
        R<T> r = new R<>();
        r.success = true;
        return r;
    }

    public static <T> R<T> error(String message) {
        if (message == null || message.isEmpty()) {
            throw new RuntimeException("错误信息为空");
        }
        R<T> r = new R<>();
        r.success = false;
        r.message = message;
        return r;
    }

    public R<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public R<T> setData(T data) {
        this.data = data;
        return this;
    }
}